package com.fs.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.entity.MaterCategoryCondition;
import com.fs.entity.Materialcategory;
import com.fs.entity.ResponseData;
import com.fs.entity.StuCondition;
import com.fs.service.IMaterialcategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-06-12
 */
@RestController
@RequestMapping("/materialcategory")
public class MaterialcategoryController {
    @Autowired
    IMaterialcategoryService materialcategoryService;
    //分页查询材料类别
    @GetMapping("/querymatcategaryByPageAndCondition")
    public ResponseData querymatcategaryByPageAndCondition(MaterCategoryCondition materCategoryCondition){
        Page page=materialcategoryService.queryByPageAndCondition(materCategoryCondition);
        return ResponseData.ok(page);
    }
    //修改材料类别
    @PutMapping("/updateMatcategary")
    public ResponseData updateMatcategary(Materialcategory materialcategory){
        materialcategoryService.updateMaterCategory(materialcategory);
        return ResponseData.ok();
    }
    //获取材料类别名称1111
    @GetMapping("/GetKind")
    public ResponseData getKind(int mckind){
        List<Materialcategory> categories = materialcategoryService.getKind(mckind);
        return ResponseData.ok(categories);

    }
    @GetMapping("/ConfirmKind")
    public ResponseData ConfirmKind(int kid, HttpSession session){
        session.setAttribute("kid",kid);
        return ResponseData.ok();
    }

    //新增材料类别
    @PostMapping("/AddMaterCategory")
    public ResponseData AddMaterCategory(Materialcategory materialcategory){
        if(materialcategoryService.AddMaterCategory(materialcategory))
        {
            return ResponseData.ok();
        }
        return ResponseData.error("新增失败");
    }
}
